{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Kids With the Greatest Number of Candies"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: kidsWithCandies"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #拥有最多糖果的孩子"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个数组&nbsp;<code>candies</code>&nbsp;和一个整数&nbsp;<code>extraCandies</code>&nbsp;，其中&nbsp;<code>candies[i]</code>&nbsp;代表第 <code>i</code> 个孩子拥有的糖果数目。</p>\n",
    "\n",
    "<p>对每一个孩子，检查是否存在一种方案，将额外的&nbsp;<code>extraCandies</code>&nbsp;个糖果分配给孩子们之后，此孩子有 <strong>最多</strong>&nbsp;的糖果。注意，允许有多个孩子同时拥有 <strong>最多</strong>&nbsp;的糖果数目。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>candies = [2,3,5,1,3], extraCandies = 3\n",
    "<strong>输出：</strong>[true,true,true,false,true] \n",
    "<strong>解释：</strong>\n",
    "孩子 1 有 2 个糖果，如果他得到所有额外的糖果（3个），那么他总共有 5 个糖果，他将成为拥有最多糖果的孩子。\n",
    "孩子 2 有 3 个糖果，如果他得到至少 2 个额外糖果，那么他将成为拥有最多糖果的孩子。\n",
    "孩子 3 有 5 个糖果，他已经是拥有最多糖果的孩子。\n",
    "孩子 4 有 1 个糖果，即使他得到所有额外的糖果，他也只有 4 个糖果，无法成为拥有糖果最多的孩子。\n",
    "孩子 5 有 3 个糖果，如果他得到至少 2 个额外糖果，那么他将成为拥有最多糖果的孩子。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>candies = [4,2,1,1,2], extraCandies = 1\n",
    "<strong>输出：</strong>[true,false,false,false,false] \n",
    "<strong>解释：</strong>只有 1 个额外糖果，所以不管额外糖果给谁，只有孩子 1 可以成为拥有糖果最多的孩子。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>candies = [12,1,12], extraCandies = 10\n",
    "<strong>输出：</strong>[true,false,true]\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>2 &lt;= candies.length &lt;= 100</code></li>\n",
    "\t<li><code>1 &lt;= candies[i] &lt;= 100</code></li>\n",
    "\t<li><code>1 &lt;= extraCandies &lt;= 50</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [kids-with-the-greatest-number-of-candies](https://leetcode.cn/problems/kids-with-the-greatest-number-of-candies/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [kids-with-the-greatest-number-of-candies](https://leetcode.cn/problems/kids-with-the-greatest-number-of-candies/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[2,3,5,1,3]\\n3', '[4,2,1,1,2]\\n1', '[12,1,12]\\n10']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def kidsWithCandies(self, a: List[int], b: int) -> List[bool]:\n",
    "        c = max(a)\n",
    "        return [x+b>=c for x in a]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:\n",
    "        maxcandies = max(candies)\n",
    "        return [candie + extraCandies >= maxcandies for candie in candies]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:\n",
    "        res = []\n",
    "        for i in range(len(candies)):\n",
    "            if candies[i]+extraCandies>=max(candies):\n",
    "                res.append(True)\n",
    "            else :\n",
    "                res.append(False)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:\n",
    "        res = []\n",
    "        num = max(candies)\n",
    "        for i in candies:\n",
    "            res.append(i + extraCandies >= num)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:\n",
    "        res = []\n",
    "        num = max(candies)\n",
    "        for i in candies:\n",
    "            res.append(i + extraCandies >= num)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:\n",
    "        m = max(candies)\n",
    "        return [(i+extraCandies)>=m for i in candies]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:\n",
    "        l = max(list(range(10)))\n",
    "        [i >= l for i in range(100000)]\n",
    "        return [c + extraCandies >= max(candies) for c in candies]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:\n",
    "        max_candy = max(candies)\n",
    "        ans = []\n",
    "        for i in candies:\n",
    "            if i + extraCandies >= max_candy:\n",
    "                ans.append(True)\n",
    "            else:\n",
    "                ans.append(False)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:\n",
    "        bools = []\n",
    "        maxc = max(candies)\n",
    "        for i in candies:\n",
    "            if i+extraCandies >= maxc:\n",
    "                bools.append(True)\n",
    "            else:\n",
    "                bools.append(False)\n",
    "        return bools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:\n",
    "        ma=max(candies)\n",
    "        i=0\n",
    "        n=len(candies)\n",
    "        res=[]\n",
    "        while i<n:\n",
    "            if candies[i]+extraCandies>=ma:\n",
    "                res.append(True)\n",
    "            else:\n",
    "                res.append(False)\n",
    "            i=i+1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:\n",
    "        max_num=max(candies)\n",
    "        return [candie + extraCandies >= max_num for candie in candies]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:\n",
    "        c=max(candies)\n",
    "        return [x+extraCandies>=c for x in candies]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:\n",
    "        maxSize = max(candies)\n",
    "        return [can + extraCandies >= maxSize for can in candies]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:\n",
    "        maxCandies = max(candies)\n",
    "        ret = [candy+extraCandies>= maxCandies for candy in candies]\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:\n",
    "        maxCandies = max(candies)\n",
    "        ret = [candy + extraCandies >= maxCandies for candy in candies]\n",
    "        return ret"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
